throwing_ptr
Smart pointers that throw on dereference if null
|
unique_ptr that manages a dynamically-allocated array of objects More...
Public Types | |
typedef std::unique_ptr< T[], Deleter > | std_unique_ptr_type |
type of the wrapped std::unique_ptr. More... | |
typedef std::unique_ptr< T[], Deleter >::pointer | pointer |
type of the pointer to the pointed objects. More... | |
typedef std::unique_ptr< T[], Deleter >::element_type | element_type |
type of the pointed objects. More... | |
typedef std::unique_ptr< T[], Deleter >::deleter_type | deleter_type |
type of the deleter. More... | |
Public Member Functions | |
TSP_CONSTEXPR | unique_ptr () TSP_NOEXCEPT=default |
Constructs a throwing::unique_ptr that owns nothing. More... | |
TSP_CONSTEXPR | unique_ptr (std::nullptr_t) TSP_NOEXCEPT |
Constructs a throwing::unique_ptr that owns nothing. More... | |
template<class U > | |
unique_ptr (U ptr) TSP_NOEXCEPT | |
Constructs a throwing::unique_ptr which owns p. More... | |
template<class U > | |
unique_ptr (U ptr, typename std::conditional< std::is_reference< Deleter >::value, Deleter, const Deleter &>::type d1) TSP_NOEXCEPT | |
Constructs a throwing::unique_ptr object which owns ptr. More... | |
template<class U > | |
unique_ptr (U ptr, typename std::remove_reference< Deleter >::type &&d2) TSP_NOEXCEPT | |
Constructs a throwing::unique_ptr object which owns ptr. More... | |
unique_ptr (unique_ptr &&u) TSP_NOEXCEPT | |
Constructs a unique_ptr by transferring ownership from u to *this. More... | |
template<class U , class E > | |
unique_ptr (unique_ptr< U, E > &&u) TSP_NOEXCEPT | |
Constructs a unique_ptr by transferring ownership from u to *this, where u is constructed with a specified deleter (E). More... | |
template<class U , class E > | |
unique_ptr (std::unique_ptr< U, E > &&u) TSP_NOEXCEPT | |
Constructs a unique_ptr by transferring ownership from u to *this, where u is constructed with a specified deleter (E). More... | |
~unique_ptr ()=default | |
Destructor If get() == nullptr there are no effects. Otherwise, the owned object is destroyed via get_deleter()(get()) on the underlying unique_ptr. More... | |
unique_ptr & | operator= (unique_ptr &&r) TSP_NOEXCEPT |
Assignment operator. More... | |
template<class U , class E > | |
unique_ptr & | operator= (unique_ptr< U, E > &&r) TSP_NOEXCEPT |
Assignment operator. More... | |
template<class U , class E > | |
unique_ptr & | operator= (std::unique_ptr< U, E > &&r) TSP_NOEXCEPT |
Assignment from std::unique_ptr operator. More... | |
unique_ptr & | operator= (std::nullptr_t) TSP_NOEXCEPT |
Assignment operator. More... | |
pointer | release () TSP_NOEXCEPT |
Releases the ownership of the managed object if any. More... | |
void | reset (pointer ptr=pointer()) TSP_NOEXCEPT |
Replaces the managed object. More... | |
template<class U > | |
void | reset (U ptr) TSP_NOEXCEPT |
Replaces the managed object. More... | |
void | reset (std::nullptr_t ptr=nullptr) TSP_NOEXCEPT |
Equivalent to reset(pointer()) More... | |
void | swap (unique_ptr &other) TSP_NOEXCEPT |
Swaps the managed objects and associated deleters of *this and another unique_ptr object other. More... | |
pointer | get () const TSP_NOEXCEPT |
Returns a pointer to the managed object or nullptr if no object is owned. More... | |
Deleter & | get_deleter () TSP_NOEXCEPT |
Returns the deleter object which would be used for destruction of the managed object. More... | |
const Deleter & | get_deleter () const TSP_NOEXCEPT |
Returns the deleter object which would be used for destruction of the managed object. More... | |
operator bool () const TSP_NOEXCEPT | |
Checks whether *this owns an object, i.e. whether get() != nullptr. More... | |
T & | operator[] (size_t i) const |
provides access to elements of an array managed by a unique_ptr. More... | |
std_unique_ptr_type & | get_std_unique_ptr () TSP_NOEXCEPT |
Returns reference to the wrapped std::unique_ptr. More... | |
const std_unique_ptr_type & | get_std_unique_ptr () const TSP_NOEXCEPT |
Returns const reference to the wrapped std::unique_ptr. More... | |
Friends | |
template<typename OtherT , typename OtherDeleter > | |
class | unique_ptr |
unique_ptr that manages a dynamically-allocated array of objects
throwing::unique_ptr is a smart pointer that owns and manages another object through a pointer and disposes of that object when the unique_ptr goes out of scope.
The object is disposed of using the associated deleter when either of the following happens:
The object is disposed of using a potentially user-supplied deleter by calling get_deleter()(ptr). The default deleter uses the delete operator, which destroys the object and deallocates the memory.
A unique_ptr may alternatively own no object, in which case it is called empty.
Definition at line 328 of file unique_ptr.hpp.
typedef std::unique_ptr<T[], Deleter>::deleter_type throwing::unique_ptr< T[], Deleter >::deleter_type |
type of the deleter.
Definition at line 337 of file unique_ptr.hpp.
typedef std::unique_ptr<T[], Deleter>::element_type throwing::unique_ptr< T[], Deleter >::element_type |
type of the pointed objects.
Definition at line 335 of file unique_ptr.hpp.
typedef std::unique_ptr<T[], Deleter>::pointer throwing::unique_ptr< T[], Deleter >::pointer |
type of the pointer to the pointed objects.
Definition at line 333 of file unique_ptr.hpp.
typedef std::unique_ptr<T[], Deleter> throwing::unique_ptr< T[], Deleter >::std_unique_ptr_type |
type of the wrapped std::unique_ptr.
Definition at line 331 of file unique_ptr.hpp.
|
default |
Constructs a throwing::unique_ptr that owns nothing.
Value-initializes the stored pointer and the stored deleter. Requires that Deleter is DefaultConstructible and that construction does not throw an exception.
|
inline |
Constructs a throwing::unique_ptr that owns nothing.
Value-initializes the stored pointer and the stored deleter. Requires that Deleter is DefaultConstructible and that construction does not throw an exception.
Definition at line 356 of file unique_ptr.hpp.
|
inlineexplicit |
Constructs a throwing::unique_ptr which owns p.
Initialises the stored pointer with ptr and value-initialises the stored deleter.
Requires that Deleter is DefaultConstructible and that construction does not throw an exception.
This constructor is ill-formed if Deleter is of pointer or reference type. (until C++17)
This overload only participates in overload resolution if std::is_default_constructible<Deleter>::value is true and Deleter is not a pointer type. The program is ill-formed if this constructor is selected by class template argument deduction. (since C++17)
This overload will not participate in overload resolution unless one of the following is true:
Definition at line 381 of file unique_ptr.hpp.
|
inline |
Constructs a throwing::unique_ptr object which owns ptr.
Initialises the stored pointer with ptr and initialises the stored deleter with d1
This overload will not participate in overload resolution unless one of the following is true:
Definition at line 398 of file unique_ptr.hpp.
|
inline |
Constructs a throwing::unique_ptr object which owns ptr.
Initialises the stored pointer with ptr. Moves d2 into stored_deleter.
This overload will not participate in overload resolution unless one of the following is true:
Definition at line 416 of file unique_ptr.hpp.
|
inline |
Constructs a unique_ptr by transferring ownership from u to *this.
If Deleter is not a reference type, requires that it is nothrow-MoveConstructible (if Deleter is a reference, get_deleter() and u.get_deleter() after move construction reference the same value)
Definition at line 427 of file unique_ptr.hpp.
|
inline |
Constructs a unique_ptr by transferring ownership from u to *this, where u is constructed with a specified deleter (E).
It depends upon whether E is a reference type, as following: a) if E is a reference type, this deleter is copy constructed from u's deleter (requires that this construction does not throw) b) if E is a non-reference type, this deleter is move constructed from u's deleter (requires that this construction does not throw)
This constructor only participates in overload resolution if all of the following are true: a) unique_ptr<U, E>::pointer is implicitly convertible to pointer b) U is an array type c) pointer is the same type as element_type* d) unique_ptr<U,E>::pointer is the same type as unique_ptr<U,E>::element_type* e) unique_ptr<U,E>::element_type(*)[] is convertible to element_type(*)[] f) Either Deleter is a reference type and E is the same type as Deleter, or Deleter is not a reference type and E is implicitly convertible to Deleter.
Definition at line 451 of file unique_ptr.hpp.
|
inline |
Constructs a unique_ptr by transferring ownership from u to *this, where u is constructed with a specified deleter (E).
It depends upon whether E is a reference type, as following: a) if E is a reference type, this deleter is copy constructed from u's deleter (requires that this construction does not throw) b) if E is a non-reference type, this deleter is move constructed from u's deleter (requires that this construction does not throw)
This constructor only participates in overload resolution if all of the following are true: a) unique_ptr<U, E>::pointer is implicitly convertible to pointer b) U is an array type c) pointer is the same type as element_type* d) unique_ptr<U,E>::pointer is the same type as unique_ptr<U,E>::element_type* e) unique_ptr<U,E>::element_type(*)[] is convertible to element_type(*)[] f) Either Deleter is a reference type and E is the same type as Deleter, or Deleter is not a reference type and E is implicitly convertible to Deleter.
Definition at line 476 of file unique_ptr.hpp.
|
default |
Destructor If get() == nullptr there are no effects. Otherwise, the owned object is destroyed via get_deleter()(get()) on the underlying unique_ptr.
Requires that get_deleter()(get()) does not throw exceptions.
|
inline |
Returns a pointer to the managed object or nullptr if no object is owned.
Definition at line 615 of file unique_ptr.hpp.
|
inline |
Returns the deleter object which would be used for destruction of the managed object.
Definition at line 620 of file unique_ptr.hpp.
|
inline |
Returns the deleter object which would be used for destruction of the managed object.
Definition at line 625 of file unique_ptr.hpp.
|
inline |
Returns reference to the wrapped std::unique_ptr.
Definition at line 648 of file unique_ptr.hpp.
|
inline |
Returns const reference to the wrapped std::unique_ptr.
Definition at line 652 of file unique_ptr.hpp.
|
inlineexplicit |
Checks whether *this owns an object, i.e. whether get() != nullptr.
Definition at line 630 of file unique_ptr.hpp.
|
inline |
Assignment operator.
Transfers ownership from r to *this as if by calling reset(r.release()) followed by an assignment of get_deleter() from std::forward<E>(r.get_deleter()).
If Deleter is not a reference type, requires that it is nothrow-MoveAssignable.
If Deleter is a reference type, requires that std::remove_reference<Deleter>::type is nothrow-CopyAssignable.
Definition at line 498 of file unique_ptr.hpp.
|
inline |
Assignment operator.
Transfers ownership from r to *this as if by calling reset(r.release()) followed by an assignment of get_deleter() from std::forward<E>(r.get_deleter()).
If Deleter is not a reference type, requires that it is nothrow-MoveAssignable.
If Deleter is a reference type, requires that std::remove_reference<Deleter>::type is nothrow-CopyAssignable.
Only participates in overload resolution if all of the following is true:
Definition at line 524 of file unique_ptr.hpp.
|
inline |
Assignment from std::unique_ptr operator.
Transfers ownership from r to *this as if by calling reset(r.release()) followed by an assignment of get_deleter() from std::forward<E>(r.get_deleter()).
If Deleter is not a reference type, requires that it is nothrow-MoveAssignable.
If Deleter is a reference type, requires that std::remove_reference<Deleter>::type is nothrow-CopyAssignable.
Only participates in overload resolution if all of the following is true:
Definition at line 550 of file unique_ptr.hpp.
|
inline |
Assignment operator.
Effectively the same as calling reset().
Definition at line 559 of file unique_ptr.hpp.
|
inline |
provides access to elements of an array managed by a unique_ptr.
The parameter i shall be less than the number of elements in the array; otherwise, the behavior is undefined.
throwing::null_ptr_exception<element_type> | if the unique_ptr is empty |
Definition at line 640 of file unique_ptr.hpp.
|
inline |
Releases the ownership of the managed object if any.
get() returns nullptr after the call.
Definition at line 571 of file unique_ptr.hpp.
|
inline |
Replaces the managed object.
Given current_ptr, the pointer that was managed by *this, performs the following actions, in this order:
Definition at line 583 of file unique_ptr.hpp.
|
inline |
Replaces the managed object.
Given current_ptr, the pointer that was managed by *this, performs the following actions, in this order:
Will only participate in overload resolution if either:
Definition at line 601 of file unique_ptr.hpp.
|
inline |
|
inline |
Swaps the managed objects and associated deleters of *this and another unique_ptr object other.
Definition at line 610 of file unique_ptr.hpp.
|
friend |
Definition at line 340 of file unique_ptr.hpp.